define(function (require, exports, module) {

    require("apps/easyui");
    exports.init = function (ctx, uuid) {
        var page = new $.PageDomFactory(uuid);
        page.getJqDom("form-user-update-info").find(".easyui-validatebox").validatebox();

        function user_edit_save(pageContext) {
            var postForm = pageContext.getJqDom("form-user-update-info");
            if (!postForm.form('validate')) {
                return false;
            }
            $("body").wait("start", "保存中,请稍候.");
            var postData = postForm.serializeJson();
            $.post(postForm.attr(
                    "action")
                    + "?random=" + Math.random(), $.utils.buildJson(postData),
                function (json) {
                    $("body").wait("end");
                    if ($.isPlainObject(json) && json.error) {
                        $.messager.alert('信息',
                            data.msg, 'info');
                    } else {
                        $.messager.alert('信息',
                            '保存成功', 'info');
                        window.location.href = ctx + "/app/api/home/index";
                    }
                }, "json");
        }

        page.getJqDom("userHeadList").combobox({
            url: ctx + "/app/api/file/userHeadList",
            valueField: 'id',
            textField: 'text',
            onLoadSuccess: function(){
                page.getJqDom("userHeadTd").find(".textbox-text").css({"display":"none"});
                page.getJqDom("userHeadTd").find(".textbox-icon").css({"width":"400px"});
                $(".combobox-item").css({"padding":"5px","display":"inline-block"});
            },
            onSelect: function(record){
                page.getJqDom('userHead').attr("src", ctx + "/print" + record.id);
            }
        });
        require("apps/file");
        page.getJqDom('uploadCover').cropImageUpload({
            onCropComplete:function(event, ins){
                var file = ins.file;
                page.getJqDom('uploadCover').val(file);
                page.getJqDom('userHead').attr("src", ctx + "/print" + file);
            }
        });
        require("apps/tag");
        page.getJqDom("ipAddress").tagEditor({
            delimiter: ',',
            clickDelete: true,
            placeholder: 'IP地址..'
        });
        page.getJqDom("save").linkbutton({
            onClick:function(){
                user_edit_save(page);
            }
        })
        page.getJqDom("cancel").linkbutton({
            onClick:function(){
                window.location.href = ctx + "/app/api/home/index";
            }
        })
    }
});
